package org.example.service.impl;

import org.example.dto.CounterDto;
import org.example.factory.Counter;
import org.example.factory.CounterFactory;
import org.example.service.CounterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @FileName CounterServiceImpl
 * @Description
 * @Author coderfun
 * @selfDesc coding in fun
 * @date 2024-11-02
 **/
@Service
public class CounterServiceImpl implements CounterService {
    @Autowired
    private  CounterFactory counterFactory;
    @Override
    public Boolean add(CounterDto counterDto) {
        Counter counter = counterFactory.getKindOfCounter(counterDto.getKind());
        Boolean add = counter.add(counterDto);
        return add;
    }

    @Override
    public Boolean sub(CounterDto counterDto) {
        Counter counter = counterFactory.getKindOfCounter(counterDto.getKind());
        Boolean sub = counter.sub(counterDto);
        return sub;
    }

    @Override
    public Integer select(CounterDto counterDto) {
        Counter counter = counterFactory.getKindOfCounter(counterDto.getKind());
        int count = counter.select(counterDto);
        return count;
    }
}
